*************************************************************************
* "Compliance, definance and the dependency trap" [RegGov-04-2021-0140]
*
* Replication files
* Contact: bernhard.reinsberg@glasgow.ac.uk
*************************************************************************

* Data
*************************************************************************

  use "R&G-replication-main.dta", clear  
    
  qui g lngdppc=ln(gdppc_WDI)
  qui g lnloan=ln(loanquota)
  qui g lnoda=asinh(oda_pc)
 
  qui g anyinter=(intpermcor==1 |inttemp==1)
  lab var anyinter "Any interruption"   
  g lnw=ln(1+totw)
  lab var lnw "Number of waivers"
  
  g tp=0
  replace tp=1 if ayear>=1990
  replace tp=2 if ayear>=2000
  lab var tp "Time period"
  
  cmp setup
  qui xi:reg lnw i.cid i.tp i.ayear i.regid
  global C _Icid* 
  global T _Itp* 
    
  egen regbastart=sum(BA2TOT), by(regid ayear)
  egen n=count(BA2TOT), by(regid ayear)
  g iv=(regbastart-BA2TOT)/(n-1)
  lab var iv "Average number of conditions in other regional programs in same start year"

  egen regstart=sum(SCB), by(regid ayear)
  egen ns=count(SCB), by(regid ayear)
  g ivs=(regstart-SCB)/(n-1)
  
  egen regqstart=sum(QCB), by(regid ayear)
  egen nq=count(QCB), by(regid ayear)
  g ivq=(regqstart-QCB)/(n-1)

  replace loanquota=loanquota/100

  

* Compliance
**************************************************************************

* Main findings
***************
  
* Variable definition

  global Ctrl lnw adur loanquota _It* _Iregid*
  global Ctrl0 lnw adur loanquota _Iay*
  global Econ0  lngdppc gdp_growth reserves_WDI cab_gdp
  global Pol0  p_polity2 polconiii left v2x_corr_VDEM
  global IntPol0  unsc_DSV s_unga3g7 s_unga3us  
  global Econ1  dintrus anycrisis dres 
  global Pol1 dpolity dpolcon anyexelec 


* CMP estimation 

  g lnSCB=ln(1+SCB)
  g lnQCB=ln(1+QCB)

  qui g lnsreg=ln(1+regstart)
  qui g lnqreg=ln(1+regqstart)

  mat B=J(8,5,0)

  qui cmp (anyint=lnSCB lnQCB $Ctrl) (lnSCB=lnsreg $Ctrl) (lnQCB=lnqreg $Ctrl), indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store a11
  mat B[1,1]=e(N1)
  qui test [lnSCB]lnsreg 
  mat B[5,1]=`r(chi2)'
  qui test [lnQCB]lnqreg 
  mat B[8,1]=`r(chi2)'
  mat B[3,1]=e(N2)
  mat B[6,1]=e(N3)
  qui probit anyint lnSCB lnQCB $Ctrl
  mat B[2,1]=e(r2_p)
  qui reg lnSCB lnsreg $Ctrl
  mat B[4,1]=e(r2_a)
  qui reg lnQCB lnqreg $Ctrl
  mat B[7,1]=e(r2_a)
  
  qui cmp (anyint=lnSCB lnQCB $Econ1 $Pol1 $Ctrl) (lnSCB=lnsreg $Econ1 $Pol1 $Ctrl) (lnQCB=lnqreg $Econ1 $Pol1 $Ctrl), indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store a12
  mat B[1,2]=e(N1)
  qui test [lnSCB]lnsreg 
  mat B[5,2]=`r(chi2)'
  qui test [lnQCB]lnqreg 
  mat B[8,2]=`r(chi2)'
  mat B[3,2]=e(N2)
  mat B[6,2]=e(N3)
  qui probit anyint lnSCB lnQCB $Econ1 $Pol1 $Ctrl
  mat B[2,2]=e(r2_p)
  qui reg lnSCB lnsreg $Econ1 $Pol1 $Ctrl
  mat B[4,2]=e(r2_a)
  qui reg lnQCB lnqreg $Econ1 $Pol1 $Ctrl
  mat B[7,2]=e(r2_a)
  
  qui cmp (anyint=lnSCB lnQCB $Econ0 $Pol0 $Ctrl) (lnSCB=lnsreg $Econ0 $Pol0 $Ctrl) (lnQCB=lnqreg $Econ0 $Pol0 $Ctrl), indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store a13
  mat B[1,3]=e(N1)
  qui test [lnSCB]lnsreg 
  mat B[5,3]=`r(chi2)'
  qui test [lnQCB]lnqreg 
  mat B[8,3]=`r(chi2)'
  mat B[3,3]=e(N2)
  mat B[6,3]=e(N3)
  qui probit anyint lnSCB lnQCB $Econ0 $Pol0 $Ctrl
  mat B[2,3]=e(r2_p)
  qui reg lnSCB lnsreg $Econ0 $Pol0 $Ctrl
  mat B[4,3]=e(r2_a)
  qui reg lnQCB lnqreg $Econ0 $Pol0 $Ctrl
  mat B[7,3]=e(r2_a)
  
  qui cmp (anyint=lnSCB lnQCB $IntPol0 $Ctrl) (lnSCB=lnsreg $IntPol0 $Ctrl) (lnQCB=lnqreg $IntPol0 $Ctrl), indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store a14
  mat B[1,4]=e(N1)
  qui test [lnSCB]lnsreg 
  mat B[5,4]=`r(chi2)'
  qui test [lnQCB]lnqreg 
  mat B[8,4]=`r(chi2)'
  mat B[3,4]=e(N2)
  mat B[6,4]=e(N3)
  qui probit anyint lnSCB lnQCB $IntPol0 $Ctrl
  mat B[2,4]=e(r2_p)
  qui reg lnSCB lnsreg $IntPol0 $Ctrl
  mat B[4,4]=e(r2_a)
  qui reg lnQCB lnqreg $IntPol0 $Ctrl
  mat B[7,4]=e(r2_a)
  
  qui cmp (anyint=lnSCB lnQCB $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl) (lnSCB=lnsreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl) (lnQCB=lnqreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl), indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store a15
  mat B[1,5]=e(N1)
  qui test [lnSCB]lnsreg 
  mat B[5,5]=`r(chi2)'
  qui test [lnQCB]lnqreg 
  mat B[8,5]=`r(chi2)'
  mat B[3,5]=e(N2)
  mat B[6,5]=e(N3)
  qui probit anyint lnSCB lnQCB $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl
  mat B[2,5]=e(r2_p)
  qui reg lnSCB lnsreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl
  mat B[4,5]=e(r2_a)
  qui reg lnQCB lnqreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl
  mat B[7,5]=e(r2_a)
  
** Table 1**  
estout a1* using "R&G-1.rtf", starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons _I*) 
mat li B

  ** Predicted probabilities ** 
  est restore a11
  mfx, predict(xb eq(#1)) at(lnSCB=1.456)
   * normal(0.394)=0.6531
  mfx, predict(xb eq(#1)) at(lnSCB=1.666)
   * normal(0.484)=0.6858
   * 3.27 PP -> 5%
  
  est restore a15
  mfx, predict(xb eq(#1)) at(lnSCB=1.456) 
   * normal(0.316)=62.4%
  mfx, predict(xb eq(#1)) at(lnSCB=1.666) 
   * normal(0.3964)=65.4%
   * 3.00 PP -> 4.8%
  
  mfx, predict(xb eq(#1)) at(lnSCB=0) 
   di normal(-.242)
    * 40.4%
  mfx, predict(xb eq(#1)) at(lnSCB=3.8)
   di normal(1.214)
    * 88.76%
  
	
* Specific issue areas with IV design 	
  
  ** t-test **
  mat D=J(5,4,0)
  local m=1
  foreach X in BA2LAB BA2PRI BA2SOE BA2FP BA2EXT{
    qui ttest `X', by(anyinter) une
	 mat D[`m',2]=`r(mu_2)'
	 mat D[`m',1]=`r(mu_1)' 
	 mat D[`m',3]=`r(mu_2)'-`r(mu_1)'
	 mat D[`m',4]=`r(t)'
	 local m=`m'+1
	 }
   
** Table 2 **
mat li D
  
  
  ** Regression **  
  mat C=J(8,3,0)
  g lnBA2TOT=ln(1+BA2TOT)
  g lnbareg=ln(regbastart)
  
  local m=1
  
  foreach X in BA2LAB BA2PRI BA2SOE {

  qui g lnX=ln(1+`X')

  qui cmp (anyint=lnX lnBA2TOT $Econ1 $Econ0 $Pol0 $Pol1 $IntPol0 $Ctrl ) (lnX=lnsreg $Econ1 $Econ0 $Pol0 $Pol1 $IntPol0 $Ctrl ) (lnBA2TOT=lnbareg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl ), indicators($cmp_probit 1 1) ro cl(cid) iterate(33)
  est store a3`m'
  mat C[1,`m']=e(N1)
  mat C[3,`m']=e(N2)
  qui test [lnX]lnsreg
  mat C[5,`m']=r(chi2)
  mat C[6,`m']=e(N3)
  qui test [lnBA2TOT]lnbareg
  mat C[8,`m']=r(chi2)
  qui probit anyint lnX lnBA2TOT $Econ1 $Econ0 $Pol0 $Pol1 $IntPol0 $Ctrl
  mat C[2,`m']=e(r2_p)
  qui reg lnX lnsreg $Econ1 $Econ0 $Pol0 $Pol1 $IntPol0 $Ctrl
  mat C[4,`m']=e(r2_w)
  qui reg lnBA2TOT lnbareg $Econ1 $Econ0 $Pol0 $Pol1 $IntPol0 $Ctrl
  mat C[7,`m']=e(r2_w)
  
  drop lnX  
  local m=`m'+1
  }

** Table 3 ** 
estout a3* using "R&G-3.rtf", starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons _I*) 
mat li C
  
  
* For financial market responses please find tables further below

** Table 4 **
** Table 5 **



* Robustness tests 
******************   

* Descriptive statistics further below

** Table I.1 **


* Probit models 

  mat A=J(2,5,0)
  
  qui probit anyinter lnSCB lnQCB $Ctrl, vce(ro)
  est store r11
  mat A[1,1]=e(N)
  mat A[2,1]=e(r2_p)
  qui probit anyinter lnSCB lnQCB $Econ1 $Pol1 $Ctrl, vce(ro)
  est store r12
  mat A[1,2]=e(N)
  mat A[2,2]=e(r2_p)
  qui probit anyinter lnSCB lnQCB $Econ0 $Pol0 $Ctrl, vce(ro)
  est store r13
  mat A[1,3]=e(N)
  mat A[2,3]=e(r2_p)
  qui probit anyinter lnSCB lnQCB $IntPol0 $Ctrl, vce(ro)
  est store r14
  mat A[1,4]=e(N)
  mat A[2,4]=e(r2_p)
  qui probit anyinter lnSCB lnQCB $Econ1 $Econ0 $Pol0 $Pol1 $IntPol0 $Ctrl, vce(ro)
  est store r15
  mat A[1,5]=e(N)
  mat A[2,5]=e(r2_p)
  
** Table I.2 **  
estout r1* using "R&G-I2.rtf", starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons _I*) 
mat li A


  
* Conditionality types

  mat C=J(2,5,0)
  local m=1
  
  foreach X in BA2LAB BA2PRI BA2SOE BA2FP BA2EXT{

  qui g lnX=ln(1+`X')

  qui probit anyint lnX lnBA2TOT $Econ1 $Econ0 $Pol0 $Pol1 $IntPol0 $Ctrl, vce(ro)
  est store r2`m'
  mat C[1,`m']=e(N)
  mat C[2,`m']=e(r2_p)
  drop lnX  
  local m=`m'+1
  }

** Table I.3 ** 
estout r2* using "R&G-I3.rtf", starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons _I*) 
mat li C
  
  

* SUR system with IV strategy 

  mat B=J(10,5,0)
  
  qui cmp (inttemp=lnSCB lnQCB $Ctrl) (intpermcor=lnSCB lnQCB $Ctrl) (lnSCB=lnsreg $Ctrl) (lnQCB=lnqreg $Ctrl), indicators($cmp_probit $cmp_probit $cmp_cont $cmp_cont) ro 
  est store r31
  mat B[1,1]=e(N1)
  qui test [lnSCB]lnsreg 
  mat B[7,1]=`r(chi2)'
  qui test [lnQCB]lnqreg 
  mat B[10,1]=`r(chi2)'
  mat B[3,1]=e(N2)
  mat B[5,1]=e(N3)
  mat B[8,1]=e(N4)
  qui probit inttemp lnSCB lnQCB $Ctrl
  mat B[2,1]=e(r2_p)
  qui probit intpermcor lnSCB lnQCB $Ctrl
  mat B[4,1]=e(r2_p)
  qui reg lnSCB lnsreg $Ctrl
  mat B[6,1]=e(r2_a)
  qui reg lnQCB lnqreg $Ctrl
  mat B[9,1]=e(r2_a)
  
  qui cmp (inttemp=lnSCB lnQCB $Econ1 $Pol1 $Ctrl) (intpermcor=lnSCB lnQCB $Econ1 $Pol1 $Ctrl) (lnSCB=lnsreg $Econ1 $Pol1 $Ctrl) (lnQCB=lnqreg $Econ1 $Pol1 $Ctrl), indicators($cmp_probit $cmp_probit $cmp_cont $cmp_cont) ro 
  est store r32
  mat B[1,2]=e(N1)
  qui test [lnSCB]lnsreg 
  mat B[7,2]=`r(chi2)'
  qui test [lnQCB]lnqreg 
  mat B[10,2]=`r(chi2)'
  mat B[3,2]=e(N2)
  mat B[5,2]=e(N3)
  mat B[8,2]=e(N4)
  qui probit inttemp lnSCB lnQCB $Ctrl
  mat B[2,2]=e(r2_p)
  qui probit intpermcor lnSCB lnQCB $Ctrl
  mat B[4,2]=e(r2_p)
  qui reg lnSCB lnsreg $Ctrl
  mat B[6,2]=e(r2_a)
  qui reg lnQCB lnqreg $Ctrl
  mat B[9,2]=e(r2_a)
  
  qui cmp (inttemp=lnSCB lnQCB $Econ0 $Pol0 $Ctrl) (intpermcor=lnSCB lnQCB $Econ0 $Pol0 $Ctrl) (lnSCB=lnsreg $Econ0 $Pol0 $Ctrl) (lnQCB=lnqreg $Econ0 $Pol0 $Ctrl), indicators($cmp_probit $cmp_probit $cmp_cont $cmp_cont) ro 
  est store r33
  mat B[1,3]=e(N1)
  qui test [lnSCB]lnsreg 
  mat B[7,3]=`r(chi2)'
  qui test [lnQCB]lnqreg 
  mat B[10,3]=`r(chi2)'
  mat B[3,3]=e(N2)
  mat B[5,3]=e(N3)
  mat B[8,3]=e(N4)
  qui probit inttemp lnSCB lnQCB $Econ0 $Pol0 $Ctrl
  mat B[2,3]=e(r2_p)
  qui probit intpermcor lnSCB lnQCB $Econ0 $Pol0 $Ctrl
  mat B[4,3]=e(r2_p)
  qui reg lnSCB lnsreg $Econ0 $Pol0  $Ctrl
  mat B[6,3]=e(r2_a)
  qui reg lnQCB lnqreg $Econ0 $Pol0 $Ctrl
  mat B[9,3]=e(r2_a)
  
  qui cmp (inttemp=lnSCB lnQCB $IntPol0 $Ctrl) (intpermcor=lnSCB lnQCB $IntPol0 $Ctrl) (lnSCB=lnsreg $IntPol0 $Ctrl) (lnQCB=lnqreg $IntPol0 $Ctrl), indicators($cmp_probit $cmp_probit $cmp_cont $cmp_cont) ro 
  est store r34
  mat B[1,4]=e(N1)
  qui test [lnSCB]lnsreg 
  mat B[7,4]=`r(chi2)'
  qui test [lnQCB]lnqreg 
  mat B[10,4]=`r(chi2)'
  mat B[3,4]=e(N2)
  mat B[5,4]=e(N3)
  mat B[8,4]=e(N4)
  qui probit inttemp lnSCB lnQCB $IntPol0 $Ctrl
  mat B[2,4]=e(r2_p)
  qui probit intpermcor lnSCB lnQCB $IntPol0 $Ctrl
  mat B[4,4]=e(r2_p)
  qui reg lnSCB lnsreg $IntPol0 $Ctrl
  mat B[6,4]=e(r2_a)
  qui reg lnQCB lnqreg $IntPol0 $Ctrl
  mat B[9,4]=e(r2_a)
  
  qui cmp (inttemp=lnSCB lnQCB $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl) (intpermcor=lnSCB lnQCB $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl) (lnSCB=lnsreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl) (lnQCB=lnqreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl), indicators($cmp_probit $cmp_probit $cmp_cont $cmp_cont) ro 
  est store r35
  mat B[1,5]=e(N1)
  qui test [lnSCB]lnsreg 
  mat B[7,5]=`r(chi2)'
  qui test [lnQCB]lnqreg 
  mat B[10,5]=`r(chi2)'
  mat B[3,5]=e(N2)
  mat B[5,5]=e(N3)
  mat B[8,5]=e(N4)
  qui probit inttemp lnSCB lnQCB $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl
  mat B[2,5]=e(r2_p)
  qui probit intpermcor lnSCB lnQCB $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl
  mat B[4,5]=e(r2_p)
  qui reg lnSCB lnsreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl
  mat B[6,5]=e(r2_a)
  qui reg lnQCB lnqreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl
  mat B[9,5]=e(r2_a)

** Table I.4 **  
estout r3* using "R&G-I4.rtf", starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons _I*)   
mat li B  

  
  
* Different samples and additional controls 

  mat R=J(8,6,0)

  ** Non-developed countries **
  qui probit anyinter lnSCB lnQCB $Econ1 $Econ0 $Pol0 $Pol1 $IntPol0 $Ctrl if incid!=1, vce(ro)
  est store r41
  mat R[1,1]=e(N)
  mat R[2,1]=e(r2_p)
    
  qui cmp (anyinter=lnSCB lnQCB $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl) (lnSCB=lnsreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl) (lnQCB=lnqreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl) if incid!=1, indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store r42
  mat R[1,2]=e(N1)
  mat R[3,2]=e(N2)
  mat R[6,2]=e(N3)
  qui test [lnSCB]lnsreg
  mat R[5,2]=`r(chi2)'
  qui test [lnQCB]lnqreg
  mat R[8,2]=`r(chi2)'
  qui probit anyinter lnSCB lnQCB $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl
  mat R[2,2]=e(r2_p)
  qui reg lnSCB lnsreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl
  mat R[4,2]=e(r2_a)
  qui reg lnQCB lnqreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl
  mat R[7,2]=e(r2_a)
  	
  ** Controlling for non-binding conditions **
  qui g lnSBs=ln(1+SBsTOT)
  qui g lnIBs=ln(1+IBsTOT)
  qui probit anyinter lnSCB lnQCB lnSBs lnIBs $Econ1 $Econ0 $Pol0 $Pol1 $IntPol0 $Ctrl, vce(ro)
  est store r43
  mat R[1,3]=e(N)
  mat R[2,3]=e(r2_p)    
    
  qui cmp (anyinter=lnSCB lnQCB lnSBs lnIBs $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl) (lnSCB=lnsreg lnSBs lnIBs $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl) (lnQCB=lnqreg lnSBs lnIBs $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl), indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store r44 
  mat R[1,4]=e(N1)
  mat R[3,4]=e(N2)
  mat R[6,4]=e(N3)
  qui test [lnSCB]lnsreg
  mat R[5,4]=`r(chi2)'
  qui test [lnQCB]lnqreg
  mat R[8,4]=`r(chi2)'
  qui probit anyinter lnSCB lnQCB $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl
  mat R[2,4]=e(r2_p)
  qui reg lnSCB lnsreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl
  mat R[4,4]=e(r2_a)
  qui reg lnQCB lnqreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl
  mat R[7,4]=e(r2_a)

  ** Outliers **
  preserve   
    collapse (mean)intpermcor SCB QCB, by(cid iso3)
	twoway (scatter intpermcor SCB, mlab(iso3)) (lfit intpermcor SCB), xtitle(Structural conditions) ytitle(Share of programs permanently interrupted) legend(off) scheme(s1mono)
	** Figure I.1 **
	graph export "R&G-Fig-I1.png", width(1800) replace 
  restore 	
  
  g outlier=(iso3=="UZB"|iso3=="MDA"|iso3=="MNG"|iso3=="KAZ")
 
  qui probit anyint lnSCB lnQCB $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl if outlier!=1, ro 	
  est store r45
  mat R[1,5]=e(N)
  mat R[2,5]=e(r2_p)
 
  qui cmp (anyint=lnSCB lnQCB $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl) (lnSCB=lnsreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl) (lnQCB=lnqreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl) if outlier!=1, indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store r46
  mat R[1,6]=e(N1)
  mat R[3,6]=e(N2)
  mat R[6,6]=e(N3)
  qui test [lnSCB]lnsreg
  mat R[5,6]=`r(chi2)'
  qui test [lnQCB]lnqreg
  mat R[8,6]=`r(chi2)'
  qui probit anyinter lnSCB lnQCB $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl if outlier!=1
  mat R[2,6]=e(r2_p)
  qui reg lnSCB lnsreg $Ctrl $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0
  mat R[4,6]=e(r2_a)
  qui reg lnQCB lnqreg $Ctrl $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0
  mat R[7,6]=e(r2_a)
  
** Table I.5 **  
estout r4* using "R&G-I5.rtf", starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons _I*) 
mat li R    
    
  
* Year-fixed effects and country-fixed effects

  mat R=J(8,4,0)
  global S1 lnw adur loanquota _Iregid* _Iayear*
  global S2 $S1 $Econ0 $Pol0 $IntPol0 dintrus dres dpolity dpolcon 

  ** Year-fixed effects **
  qui cmp (anyint=lnSCB lnQCB $S1) (lnSCB=lnsreg $S1) (lnQCB=lnqreg $S1), indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store r51
  mat R[1,1]=e(N1)
  qui test [lnSCB]lnsreg 
  mat R[5,1]=`r(chi2)'
  qui test [lnQCB]lnqreg 
  mat R[8,1]=`r(chi2)'
  mat R[3,1]=e(N2)
  mat R[6,1]=e(N3)
  qui probit anyint lnSCB lnQCB $S1
  mat R[2,1]=e(r2_p)
  qui reg lnSCB lnsreg $S1
  mat R[4,1]=e(r2_a)
  qui reg lnQCB lnqreg $S1
  mat R[7,1]=e(r2_a)
  
  qui cmp (anyint=lnSCB lnQCB $S2) (lnSCB=lnsreg $S2) (lnQCB=lnqreg $S2), indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store r52
  mat R[1,2]=e(N1)
  qui test [lnSCB]lnsreg 
  mat R[5,2]=`r(chi2)'
  qui test [lnQCB]lnqreg 
  mat R[8,2]=`r(chi2)'
  mat R[3,2]=e(N2)
  mat R[6,2]=e(N3)
  qui probit anyint lnSCB lnQCB $S2
  mat R[2,2]=e(r2_p)
  qui reg lnSCB lnsreg $S2
  mat R[4,2]=e(r2_a)
  qui reg lnQCB lnqreg $S2
  mat R[7,2]=e(r2_a)
  
  ** Country-fixed effects **
  global S1 lnw adur loanquota _Itp* _Icid*
  global S2 $S1 $Econ0 $Pol0 $IntPol0 dintrus dres dpolity dpolcon 
  set matsize 800
  
  qui cmp (anyint=lnSCB lnQCB _Icid* $S1) (lnSCB=lnsreg $S1) (lnQCB=lnqreg $S1), indicators($cmp_cont $cmp_cont $cmp_cont) ro 
  est store r53
  mat R[1,3]=e(N1)
  qui test [lnSCB]lnsreg 
  mat R[5,3]=`r(chi2)'
  qui test [lnQCB]lnqreg 
  mat R[8,3]=`r(chi2)'
  mat R[3,3]=e(N2)
  mat R[6,3]=e(N3)
  qui reg anyint lnSCB lnQCB $S1
  mat R[2,3]=e(r2_a)
  qui reg lnSCB lnsreg $S1
  mat R[4,3]=e(r2_a)
  qui reg lnQCB lnqreg $S1
  mat R[7,3]=e(r2_a)
  
  qui cmp (anyint=lnSCB lnQCB $S2) (lnSCB=lnsreg $S2) (lnQCB=lnqreg $S2), indicators($cmp_cont $cmp_cont $cmp_cont) ro 
  est store r54
  mat R[1,4]=e(N1)
  qui test [lnSCB]lnsreg 
  mat R[5,4]=`r(chi2)'
  qui test [lnQCB]lnqreg 
  mat R[8,4]=`r(chi2)'
  mat R[3,4]=e(N2)
  mat R[6,4]=e(N3)
  qui reg anyint lnSCB lnQCB $S2
  mat R[2,4]=e(r2_a)
  qui reg lnSCB lnsreg $S2
  mat R[4,4]=e(r2_a)
  qui reg lnQCB lnqreg $S2
  mat R[7,4]=e(r2_a)
  
** Table I.6 **  
estout r5* using "R&G-I6.rtf", starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_*)
mat li R


* Alternative instrument 

  mat B=J(8,5,0)
  egen m1=mean(SCB), by(cid)
  egen m2=mean(QCB), by(cid)
  g lnm1=ln(1+m1)
  g lnm2=ln(1+m2)
  g iv1=lnm1*nUnder
  g iv2=lnm2*nUnder 
  
  qui cmp (anyint=lnSCB lnQCB $Ctrl) (lnSCB=iv1 lnm1 nUnder $Ctrl) (lnQCB=iv2 lnm2 nUnder $Ctrl), indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store r61
  mat B[1,1]=e(N1)
  qui test [lnSCB]iv1 
  mat B[5,1]=`r(chi2)'
  qui test [lnQCB]iv2 
  mat B[8,1]=`r(chi2)'
  mat B[3,1]=e(N2)
  mat B[6,1]=e(N3)
  qui probit anyint lnSCB lnQCB $Ctrl
  mat B[2,1]=e(r2_p)
  qui reg lnSCB iv1 lnm1 nUnder $Ctrl
  mat B[4,1]=e(r2_a)
  qui reg lnQCB iv2 lnm2 nUnder $Ctrl
  mat B[7,1]=e(r2_a)
  
  qui cmp (anyint=lnSCB lnQCB $Econ1 $Pol1 $Ctrl) (lnSCB=iv1 lnm1 nUnder $Econ1 $Pol1 $Ctrl) (lnQCB=iv2 lnm2 nUnder $Econ1 $Pol1 $Ctrl), indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store r62
  mat B[1,2]=e(N1)
  qui test [lnSCB]iv1 
  mat B[5,2]=`r(chi2)'
  qui test [lnQCB]iv2 
  mat B[8,2]=`r(chi2)'
  mat B[3,2]=e(N2)
  mat B[6,2]=e(N3)
  qui probit anyint lnSCB lnQCB $Econ1 $Pol1 $Ctrl
  mat B[2,2]=e(r2_p)
  qui reg lnSCB iv1 lnm1 nUnder $Econ1 $Pol1 $Ctrl
  mat B[4,2]=e(r2_a)
  qui reg lnQCB iv2 lnm2 nUnder $Econ1 $Pol1 $Ctrl
  mat B[7,2]=e(r2_a)
  
  qui cmp (anyint=lnSCB lnQCB $Econ0 $Pol0 $Ctrl) (lnSCB=iv1 lnm1 nUnder $Econ0 $Pol0 $Ctrl) (lnQCB=iv2 lnm2 nUnder $Econ0 $Pol0 $Ctrl), indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store r63
  mat B[1,3]=e(N1)
  qui test [lnSCB]iv1 
  mat B[5,3]=`r(chi2)'
  qui test [lnQCB]iv2 
  mat B[8,3]=`r(chi2)'
  mat B[3,3]=e(N2)
  mat B[6,3]=e(N3)
  qui probit anyint lnSCB lnQCB $Econ0 $Pol0 $Ctrl
  mat B[2,3]=e(r2_p)
  qui reg lnSCB iv1 lnm1 nUnder $Econ0 $Pol0 $Ctrl
  mat B[4,3]=e(r2_a)
  qui reg lnQCB iv2 lnm2 nUnder $Econ0 $Pol0 $Ctrl
  mat B[7,3]=e(r2_a)
  
  qui cmp (anyint=lnSCB lnQCB $IntPol0 $Ctrl) (lnSCB=iv1 lnm1 nUnder $IntPol0 $Ctrl) (lnQCB=iv2 lnm2 nUnder $IntPol0 $Ctrl), indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store r64
  mat B[1,4]=e(N1)
  qui test [lnSCB]iv1 
  mat B[5,4]=`r(chi2)'
  qui test [lnQCB]iv2 
  mat B[8,4]=`r(chi2)'
  mat B[3,4]=e(N2)
  mat B[6,4]=e(N3)
  qui probit anyint lnSCB lnQCB $IntPol0 $Ctrl
  mat B[2,4]=e(r2_p)
  qui reg lnSCB iv1 lnm1 nUnder $IntPol0 $Ctrl
  mat B[4,4]=e(r2_a)
  qui reg lnQCB iv2 lnm2 nUnder $IntPol0 $Ctrl
  mat B[7,4]=e(r2_a)
  
  qui cmp (anyint=lnSCB lnQCB $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl) (lnSCB=iv1 lnm1 nUnder $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl) (lnQCB=iv2 lnm2 nUnder $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl), indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store r65
  mat B[1,5]=e(N1)
  qui test [lnSCB]iv1 
  mat B[5,5]=`r(chi2)'
  qui test [lnQCB]iv2 
  mat B[8,5]=`r(chi2)'
  mat B[3,5]=e(N2)
  mat B[6,5]=e(N3)
  qui probit anyint lnSCB lnQCB $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl
  mat B[2,5]=e(r2_p)
  qui reg lnSCB iv1 lnm1 nUnder $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl
  mat B[4,5]=e(r2_a)
  qui reg lnQCB iv2 lnm2 nUnder $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl
  mat B[7,5]=e(r2_a)
  
** Table I.7 **  
estout r6* using "R&G-I7.rtf", starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons _I*) 
mat li B


* Results for alternative compliance measures

** Table I.8 **
corr anyint lnw undrawn25 
pwcorr anyint lnw undrawn25, star(.05)

  mat C=J(8,4,0)

  ** Waivers **
  global Ctrl0  adur loanquota _It*
  qui reg lnw lnSCB lnQCB $Ctrl0, ro
  est store r71
   mat C[1,1]=e(N)
   mat C[2,1]=e(r2_a)
  qui reg lnw lnSCB lnQCB $Econ0 $Econ1 $Pol0 $Pol1 $IntPol0 $Ctrl0, ro 
  est store r72
   mat C[1,2]=e(N)
   mat C[2,2]=e(r2_a)
   
  qui cmp (lnw=lnSCB lnQCB $Ctrl0) (lnSCB=lnsreg $Ctrl0) (lnQCB=lnqreg $Ctrl0), indicators($cmp_cont $cmp_cont $cmp_cont) ro 
  est store r73
   mat C[1,3]=e(N1)
   mat C[3,3]=e(N2)
   mat C[6,3]=e(N3)
   qui test [lnSCB]lnsreg 
   mat C[5,3]=r(chi2)
   qui test [lnQCB]lnqreg 
   mat C[8,3]=r(chi2)
   qui reg lnw lnSCB lnQCB $Ctrl0
   mat C[2,3]=e(r2_a)
   qui reg lnSCB lnsreg $Ctrl0
   mat C[4,3]=e(r2_a)
   qui reg lnQCB lnqreg $Ctrl0
   mat C[7,3]=e(r2_a)
   
  qui cmp (lnw=lnSCB lnQCB $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl0) (lnSCB=lnsreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl0) (lnQCB=lnqreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl0), indicators($cmp_cont $cmp_cont $cmp_cont) ro 
  est store r74
   mat C[1,4]=e(N1)
   mat C[3,4]=e(N2)
   mat C[6,4]=e(N3)
   qui test [lnSCB]lnsreg 
   mat C[5,4]=r(chi2)
   qui test [lnQCB]lnqreg 
   mat C[8,4]=r(chi2)
   mat C[2,1]=e(r2_a)
   qui reg lnw lnSCB lnQCB $Ctrl0 $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 
   mat C[2,4]=e(r2_a)
   qui reg lnSCB lnsreg $Ctrl0 $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 
   mat C[4,4]=e(r2_a)
   qui reg lnQCB lnqreg $Ctrl0 $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 
   mat C[7,4]=e(r2_a)
  
** Table I.9 **  
estout r7* using "R&G-I9.rtf", starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons _I*) 
mat li C
  
  ** Undrawn funds **
  qui probit undrawn25 lnSCB lnQCB $Ctrl, ro
  est store r81
   mat C[1,1]=e(N)
   mat C[2,1]=e(r2_p)
  qui probit undrawn25 lnSCB lnQCB $Econ0 $Econ1 $Pol0 $Pol1 $IntPol0 $Ctrl, ro 
  est store r82
   mat C[1,2]=e(N)
   mat C[2,2]=e(r2_p)
   
  qui cmp (undrawn25=lnSCB lnQCB $Ctrl) (lnSCB=lnsreg $Ctrl) (lnQCB=lnqreg $Ctrl ), indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store r83
   mat C[1,3]=e(N1)
   mat C[3,3]=e(N2)
   mat C[6,3]=e(N3)
   qui test [lnSCB]lnsreg 
   mat C[5,3]=r(chi2)
   qui test [lnQCB]lnqreg 
   mat C[8,3]=r(chi2)
   qui probit undrawn25 lnSCB lnQCB $Ctrl
   mat C[2,3]=e(r2_p)
   qui reg lnSCB lnsreg $Ctrl
   mat C[4,3]=e(r2_a)
   qui reg lnQCB lnqreg $Ctrl
   mat C[7,3]=e(r2_a)
   
  qui cmp (undrawn25=lnSCB lnQCB $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl) (lnSCB=lnsreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl ) (lnQCB=lnqreg $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 $Ctrl ), indicators($cmp_probit $cmp_cont $cmp_cont) ro 
  est store r84
   mat C[1,4]=e(N1)
   mat C[3,4]=e(N2)
   mat C[6,4]=e(N3)
   qui test [lnSCB]lnsreg 
   mat C[5,4]=r(chi2)
   qui test [lnQCB]lnqreg 
   mat C[8,4]=r(chi2)
   mat C[2,1]=e(r2_a)
   qui probit undrawn25 lnSCB lnQCB $Ctrl $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 
   mat C[2,4]=e(r2_p)
   qui reg lnSCB lnsreg $Ctrl $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 
   mat C[4,4]=e(r2_a)
   qui reg lnQCB lnqreg $Ctrl $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0 
   mat C[7,4]=e(r2_a)

** Table I.10 **   
estout r8* using "R&G-I10.rtf", starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons _I*) 
mat li C

  
* Capital market response - cross-section data
**************************************************************************

* Main analysis
***************

* Investor sentiment 

  qui reg d_se_iirating inttemp iirating adur loanquota ayear if intpermcor==0, ro 
  est store a41 
  qui reg d_se_iirating inttemp iirating adur loanquota ayear _Icid* if intpermcor==0, ro 
  est store a42 
  qui reg d_se_iirating intpermcor iirating adur loanquota ayear, ro 
  est store a43 
  qui reg d_se_iirating intpermcor iirating adur loanquota ayear _Icid*, ro 
  est store a44 
  
** Table 4 **  
esttab a4* using "R&G-4.rtf", starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(*cid* _cons) stats(N r2, fmt(0 3))   
   
  ** Predicted levels ** 
  est restore a44
  mfx, at(intpermcor=0)
  mfx, at(intpermcor=1)
  

* Robustness tests
******************

* More controls

  qui reg d_se_iirating intpermcor iirating adur loanquota ayear dintrus dres dpolity dpolcon i.cid, cl(cid)
  est store s11
  qui reg d_se_iirating intpermcor iirating adur loanquota ayear lngdppc gdp_growth reserves_WDI cab_gdp p_polity2 polconiii left v2x_corr_VDEM i.cid, cl(cid)
  est store s12
  qui reg d_se_iirating intpermcor iirating adur loanquota ayear $IntPol0 i.cid, cl(cid)
  est store s13
  qui reg d_se_iirating intpermcor iirating adur loanquota ayear lngdppc gdp_growth reserves_WDI cab_gdp p_polity2 polconiii left v2x_corr_VDEM $IntPol0 i.cid, cl(cid)
  est store s14
  
** Table I.11 **  
esttab s1* using "R&G-I11.rtf", starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N r2_a, fmt(0 3)) drop(*cid* _cons)  


* Different controls 

  global Z1 lngdppc gdp_growth 
  g lncpi=asinh(infl_cpi_WDI)
  global Z2 trade_WDI lncpi
  global Z3 icrg_qog 
  
  qui reg d_se_iirating intpermcor iirating adur loanquota ayear $Z1 i.cid, cl(cid)
  est store s21
  qui reg d_se_iirating intpermcor iirating adur loanquota ayear $Z1 $Z2 i.cid, cl(cid)
  est store s22
  qui reg d_se_iirating intpermcor iirating adur loanquota ayear $Z1 $Z2 $Z3 i.cid, cl(cid)
  est store s23
  
** Table I.12 **  
esttab s2* using "R&G-I12.rtf", starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N r2_a, fmt(0 3)) drop(*cid* _cons)  


* Descriptive statistics for entire sample
  
** Table I.1 **
qui estpost su anyint inttemp intpermcor lnSCB lnQCB d_se_iirating  $Ctrl undrawn25 $Econ1 $Pol1 $Econ0 $Pol0 $IntPol0  iirating trade_WDI lncpi icrg_qog
esttab ., cells("count mean sd min max")
 
 
* Capital market response - monthly data 
************************************************************************ 
  
  use "R&G-replication-embi.dta", clear 
  encode a_ebm, g(pid)
  sort pid iso3 year month
  
  xtset pid num
  sort pid num
  
  replace embi=. if embi==0
  g lnembi=ln(embi)
  lab var lnembi "(Logged) risk premium"
  g lnaamou=ln(aamou)
  lab var lnaamou "Logged loan amount"
  
   
* Main analysis
***************

  egen anycid=max(anyint), by(cid)
  egen anyt=max(inttemp), by(cid)

  qui reg d.lnembi l.lnembi l.anyint i.year 
  est store m11
  qui reg d.lnembi l.lnembi l.anyint adur lnaamou i.year 
  est store m12
  qui reg d.lnembi l.lnembi l.anyint adur lnaamou i.year if anycid==1
  est store m13
  qui reg d.lnembi l.lnembi l.anyint adur lnaamou i.year if anyt==1
  est store m14
     
** Table 6 **	 
esttab m1* using "R&G-5.rtf", starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N r2_a, fmt(0 3)) drop(_*  *year*)  
	 
  
* Robustness test
*****************

  qui reg d.lnembi l.lnembi d.intpermcor l.intpermcor i.year if IMFnn==1, ro cl(pid)
  est store m21
  qui reg d.lnembi l.lnembi d.intpermcor l.intpermcor d.inttemp l.inttemp i.year if IMFnn==1, ro cl(pid)
  est store m22 
  qui reg d.lnembi l.lnembi d.intpermcor l.intpermcor d.inttemp l.inttemp adur lnaamou i.year if IMFnn==1, ro cl(pid)
  est store m23 
  qui reg d.lnembi l.lnembi d.intpermcor l.intpermcor d.inttemp l.inttemp adur lnaamou i.cid i.year if IMFnn==1, ro cl(pid)
  est store m24 
   
** Table I.13 **   
esttab m2* using "R&G-I13.rtf", starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N r2_a, fmt(0 3)) drop(_* *year* *cid*)  
   
   
  
* Descriptives 

  g dlnembi=d.lnembi

** Table I.14 **  
qui estpost su dlnembi lnembi anyintTS intpermcorTS inttempTS adur lnaamou      
esttab ., cells("count mean sd min max")
 
 